<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Demo07</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/3.0.2/vue.global.js"></script>
</head>

<body>
    <div id="app"></div>
</body>
<script>
    const app = Vue.createApp({
        data() {
            return {
                counter: 0
            }
        },
        methods: {
            cntadd(){
                this.counter++;
            }
        },
        template: `
                    <h2>JSPang.com</h2>
                    <counter :counter="counter" @add='cntadd'/>  
             `
    })
    app.component('Counter', {
        emits:['add'],
        props: ['counter'],
        methods: {
            cntadd(){
                this.$emit('add')
            }
        },
        template: `
        {{counter}}<button @click="cntadd">增加数量</button>
    `
    })

    const vm = app.mount("#app")
</script>

</html>